package com.specialized.background.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.specialized.common.core.domain.Result;
import com.specialized.common.redis.service.RedisService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.specialized.common.log.annotation.Log;
import com.specialized.common.log.enums.BusinessType;
import com.specialized.common.security.annotation.RequiresPermissions;
import com.specialized.background.domain.CouponTemplate;
import com.specialized.background.service.ICouponTemplateService;
import com.specialized.common.core.web.controller.BaseController;
import com.specialized.common.core.utils.poi.ExcelUtil;

/**
 * 代金卷模板Controller
 *
 * @author djh
 * @date 2024-07-30
 */
@RestController
@RequestMapping("/CouponTemplate")
public class CouponTemplateController extends BaseController {
    @Autowired
    private ICouponTemplateService couponTemplateService;
    public static final String RESOURCE_NAME = "coupontemplateList";

    /**
     * 查询代金卷模板列表
     */
//    @RequiresPermissions("background:CouponTemplate:8")
    @RequiresPermissions("background:CouponTemplate:list")
    @GetMapping("/list")
    public Result list(CouponTemplate couponTemplate) {
        startPage();
        List<CouponTemplate> list = couponTemplateService.selectCouponTemplateList(couponTemplate);
        return getDataTable(list);
    }

    /**
     * 导出代金卷模板列表
     */
    @RequiresPermissions("background:CouponTemplate:export")
    @Log(title = "代金卷模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CouponTemplate couponTemplate) {
        List<CouponTemplate> list = couponTemplateService.selectCouponTemplateList(couponTemplate);
        ExcelUtil<CouponTemplate> util = new ExcelUtil<CouponTemplate>(CouponTemplate. class);
        util.exportExcel(response, list, "代金卷模板数据");
    }

    /**
     * 获取代金卷模板详细信息
     */
    @RequiresPermissions("background:CouponTemplate:query")
    @GetMapping(value = "/{couponId}")
    public Result getInfo(@PathVariable("couponId") Long couponId) {
        return success(couponTemplateService.selectCouponTemplateByCouponId(couponId));
    }

    /**
     * 新增代金卷模板
     */
    @RequiresPermissions("background:CouponTemplate:add")
    @Log(title = "代金卷模板", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody CouponTemplate couponTemplate) {
        return toAjax(couponTemplateService.insertCouponTemplate(couponTemplate));
    }

    /**
     * 修改代金卷模板
     */
    @RequiresPermissions("background:CouponTemplate:edit")
    @Log(title = "代金卷模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody CouponTemplate couponTemplate) {
        return toAjax(couponTemplateService.updateCouponTemplate(couponTemplate));
    }

    /**
     * 删除代金卷模板
     */
    @RequiresPermissions("background:CouponTemplate:remove")
    @Log(title = "代金卷模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{couponIds}")
    public Result remove(@PathVariable Long[] couponIds) {
        return toAjax(couponTemplateService.deleteCouponTemplateByCouponIds(couponIds));
    }






}
